package com.jml.json;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JsonToNoObject {

	/**
	 * {"sites":
	 * 		[
	 * 			{"name":"jml","url":"www.jml.com"},
	 * 			{"name":"jml001","url":"http://jml001.com/"}
	 * 		]
	 * }
	 * */
	static String jsonStr = "{\"zzk\":\"nnk\",\"sites\":[{\"name\":\"jml\",\"url\":\"www.jml.com\"},{\"name\":\"jml\",\"url\":\"http://jml001.com/\"}]}";

	public static void main(String[] args) {
		System.out.println(jsonStr);
		JSONObject jsonObject = new JSONObject();
		// 将json字符串转为jsonbject
		JSONObject jsonStrObject = jsonObject.parseObject(jsonStr);
		String zzk = jsonStrObject.getString("zzk");
		System.out.println(zzk);
		//得到一个数组
		JSONArray jsonArray = jsonStrObject.getJSONArray("sites");
		for (Object object : jsonArray) {
			JSONObject stObject = (JSONObject) object;
			//转换为对应的类型
			String name = stObject.getString("name");
			String url = stObject.getString("url");
			System.out.println(name + "---" + url);
		}
	}


}
